// 列表页面的逻辑实现

// 获取元素
const contentBox = document.querySelector('.content')

// 就是获取到商品的信息渲染到页面上

// 首先要定义一个对象 里面保存的就是筛选条件
let info = {
    current: 2,
    pagesize: 12,
    search: '',
    filter: '',
    saleType: 10,
    sortType: 'id',
    sortMethod: 'ASC',
    category: ''
}
// 发送请求
getGoodsList()
async function getGoodsList() {
    let res = await $.ajax({
        url: 'http://localhost:8888/goods/list',
        data: info,
        datatype: 'json'
    })
    console.log(res);

    // 渲染页面
    let str = ''
    res.list.forEach(function (item) {
        str += `
        <li data-id="${item.goods_id}">
            <div class="show">
                <img src="${item.img_big_logo}" alt="">
                <span class="hot ${item.is_hot ? 'active' : ''}">热销</span>
                <span class="sale ${item.is_sale ? 'active' : ''}">折扣</span>
            </div>
            <div class="info">
                <p class="title"> ${item.title}</p>
                <p class="price">
                    <span class="current">￥ ${item.current_price}</span>
                    <span class="old">￥ ${item.price}</span>
                </p>
                 <button class="addCart" data-id="${item.goods_id}"></button>
            </div>
        </li>
        `
    })

    $('.container').html(str)

}


